package com.graduation.fq.student.Process;

import com.graduation.fq.student.Utils.Const;

import org.json.JSONObject;

/**
 * @author jifang
 * @version 2016/5/27.
 */
public class LoginProcess extends BaseProcess {

    private String url = "/user/login.do?";

    private String id;
    private String pwd;

    private boolean isLogin;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean login) {
        isLogin = login;
    }

    @Override
    String getRequestUrl() {
        String appendUrl = String.format("id=%s&password=%s", getId(), getPwd());
        return url + appendUrl;
    }

    @Override
    String getParameter() {
        return null;
    }

    @Override
    void onResult(JSONObject object) {
        int status = object.optInt("status");
        setStatus(status);
        if (status == Const.HTTP_SUCCESS) {
            JSONObject data = object.optJSONObject("data");
            setLogin(data.optBoolean("is_login"));
            setId(data.optString("id"));
        }
    }
}
